﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace GUI_Web
{
    public partial class DiscuEvent : System.Web.UI.Page
    {
        List<lista> listEvent = new List<lista>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                EncheList();
                CarregaGridEvent();

                Troca(true);
            }
        }

        private void Troca(bool chave)
        {
            trTbEvent.Visible = chave;
            trDiscu.Visible = !chave;
        }

        #region list event
        private void  EncheList()
        {
            listEvent.Add(new lista { Id = "1", IdEvent = "1223", Descricao = "Aula de Matemática", Lider = "Maria da Silva ", Data = "26/09/2011 - 21:00~22:40" });
            listEvent.Add(new lista { Id = "2", IdEvent = "1234", Descricao = "Aula de Física", Lider = "João da Silva ", Data = "23/09/2011 - 19:00~20:40" });
            listEvent.Add(new lista { Id = "3", IdEvent = "1239 ", Descricao = "Reunião de pais", Lider = "João da Silva ", Data = "25/09/2011 - 20:00~21:30" });
        }

        private void CarregaGridEvent()
        {
            gvEvent.DataKeyNames = new string[] { "descricao" };
            gvEvent.DataSource = listEvent;
            gvEvent.DataBind();
        }

        #endregion

        #region list coment
        private void EncheComent(int i)
        {
            Comentario items = new Comentario();
            lit01.Text = "";
            lit02.Text = "";
            lit03.Text = "";

            switch (i)
            {
                case 1:
                    lit01.Text = "<td>Ri</td><td>vai ter a correção da prova?</td>";
                    lit02.Text = "<td>Mi</td><td>como será que fui na prova?</td>";
                    break;
                case 2:
                    lit01.Text = "<td>Leo</td><td>Aula de relatividade? =p</td>";
                    break;
                case 3:
                    lit01.Text = "<td>Maria</td><td>Meus pais não poderão ir.</td>";
                    break;
            }            
        }
        #endregion

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtComent.Text != "")
            {
                lit03.Text = "<td>facens</td><td>"+txtComent.Text+"</td>";
            }
        }

        protected void gvEvent_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "discutir")
            {
                int i = Convert.ToInt32(e.CommandArgument.ToString());

                Troca(false);

                GridViewRow row = gvEvent.Rows[i - 1];

                ListItem item = new ListItem();
                item.Text = Server.HtmlDecode(row.Cells[3].Text);

                txtDescrição.Text = item.Text;

                EncheComent(i);
            }            
        }

        protected void btnVolta_Click(object sender, EventArgs e)
        {
            Troca(true);
        }

        protected void gvEvent_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            e.Row.Cells[1].Width = 100;
            e.Row.Cells[3].Width = 100;
        }
    }

    public class lista
    {
        string id, idEvent, descricao, lider, data;

        public string Id
        {
            get { return id; }
            set { id = value; }
        }

        public string Data
        {
            get { return data; }
            set { data = value; }
        }

        public string Lider
        {
            get { return lider; }
            set { lider = value; }
        }

        public string IdEvent
        {
            get { return idEvent; }
            set { idEvent = value; }
        }

        public string Descricao
        {
            get { return descricao; }
            set { descricao = value; }
        }
    }

    public class Comentario
    {
        string user;

        public string User
        {
            get { return user; }
            set { user = value; }
        }

        string descricao;

        public string Descricao
        {
            get { return descricao; }
            set { descricao = value; }
        }
    }
}